const Router = require('koa-router');
const router = new Router();

const siteLogic = require('../business-logic/site');

router.get('/sites', async(ctx, next) => {
    let query = ctx.request.query;
    let sites = await siteLogic.query(query.pageNum, query.pageCount, {
        state: 1
    });
    let total = await siteLogic.total();
    ctx.send({
        code: 200,
        data: {
            sites: sites,
            total: total
        }
    })
})

router.post('/site', async(ctx, next) => {
    let body = ctx.request.body;
    await siteLogic.save(body);
    ctx.send({
        code: 200,
        msg: 'save email success'
    });
})

router.delete('/site/:id', async(ctx, next) => {
    let id = ctx.params.id;
    await siteLogic.remove(id);
    ctx.send({
        code: 200,
        msg: 'site remove success.'
    });
})

router.put('/site', async(ctx, next) => {
    let body = ctx.request.body;
    await siteLogic.update(body);
    ctx.send({
        code: 200,
        msg: 'site update success.'
    });
})

module.exports = router;